local GoldCoin =class("GoldCoin",function() return display.newNode() end)
function GoldCoin:ctor()
 self.sprite = display.newSprite("#gold01.png",0,0);
 local frames =display.newFrames("gold%02d.png",1,15)
 local animation =display.newAnimation(frames, 1.0 / 15) 
 transition.playAnimationForever(self.sprite,animation)
 self:addChild(self.sprite)
  self.effect = display.newSprite("#goldeffect01.png",0,0);
  frames =display.newFrames("goldeffect%02d.png",1,9)
  local effectAnimation =display.newAnimation(frames, 1.0 / 60) 
  display.setAnimationCache("effectAnimation",effectAnimation)
  self.effect:setVisible(false)
  self:addChild(self.effect)
  self.sprite:retain()
  self.effect:retain()
end

function GoldCoin:onColliWithFish()
   self:removeChild(self.sprite)
   self.effect:setVisible(true)
  local animation =display.getAnimationCache("effectAnimation")
  transition.playAnimationOnce(self.effect,animation,true)
end

function GoldCoin:colliCheckWithFish(fishRect)
     if not self:getParent() or not self:getParent():getParent() then return end
     local layerX,layerY =self:getParent():getParent():getPosition()
     local uiX,uiY =self:getParent():getPosition()
     local x ,y =self:getPosition()
     local coinSize =self.sprite:getContentSize()
     local width =coinSize.width -80
     local height =coinSize.height-80
     local coinRect =CCRect(layerX+uiX+x-width/2,layerY+uiY+y-height/2,width,height)
     if fishRect:intersectsRect(coinRect) then
--         print("colliWith coin")
         self:onColliWithFish()
     end
end

return GoldCoin